package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.uuid.Seq;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysUserEdu;
import com.ruoyi.system.mapper.SysUserEduMapper;
import com.ruoyi.system.service.ISysUserEduService;
import jdk.nashorn.internal.ir.annotations.Ignore;
import org.apache.ibatis.ognl.Ognl;
import org.bouncycastle.crypto.modes.KGCMBlockCipher;
import org.springframework.beans.SimpleTypeConverter;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SysUserEduServiceImpl implements ISysUserEduService {

    @Autowired
    private SysUserEduMapper sysUserEduMapper;


    @Override
    public List<SysUserEdu> selectUserEduList(SysUserEdu sysUserEdu) {
        return sysUserEduMapper.selectSysUserEduList(sysUserEdu);
    }

    @Override
    public SysUserEdu selectUserEduByEduId(Long eduId) {
        return sysUserEduMapper.selectSysUserEduByEduId(eduId);
    }

    @Override
    public Long insertEdu(SysUserEdu sysUserEdu) {
        if (StringUtils.isNotNull(sysUserEdu.getStartDate())& StringUtils.isNotNull(sysUserEdu.getEndDate())){
            if (sysUserEdu.getStartDate().after(sysUserEdu.getEndDate())){
                throw new ServiceException("开始时间晚于结束时间，请重新选择时间");
            }
        }
        if (sysUserEdu.getEduId() != null) {
            sysUserEduMapper.updateSysUserEdu(sysUserEdu);
        } else {
            sysUserEdu.setEduId(Seq.getSeqId());
            sysUserEdu.setOrgId(SecurityUtils.getOrgId());
            sysUserEduMapper.insertSysUserEdu(sysUserEdu);
        }
        return sysUserEdu.getEduId();
    }

    @Override
    public int deleteSysUserEduByEduIds(Long[] eduIds) {
        return sysUserEduMapper.deleteSysUserEduByEduIds(eduIds);
    }
}
